package com.shujia.flink.window

import org.apache.flink.streaming.api.scala._

object Demo3CountWindow {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment


    val linesDS: DataStream[String] = env.socketTextStream("master", 8888)

    val kvDS: DataStream[(String, Int)] = linesDS.flatMap(_.split(",")).map((_, 1))

    /**
      * 滚动的统计窗口
      * 滑动的统计窗口
      *
      */
    kvDS
      .keyBy(_._1)
      .countWindow(10, 2) //每隔两条数据将最近的10条数据放到一个窗口中进行计算
      .sum(1)
      .print()


    env.execute()

  }

}
